(define (assoc key table)
  (if (null? table)
      #f
      (let ((entry (car table)))
	(if (equal? key (car entry))
	    entry
	    (assoc key (cdr table))))))

(define (assoc-split keys table k)
  (let loop ((left '()) (right '()) (table table))
    (if (null? table)
	(k left right)
	(let ((entry (car table)))
	  (if (member (car entry) keys)
	      (loop (cons entry left) right (cdr table))
	      (loop left (cons entry right) (cdr table)))))))

(define (assoc-replace table key val)
  (if (null? table)
      (list (cons key val))
      (if (eq? (caar table) key)
	  (cons (cons key val)
		(cdr table))
	  (cons (car table) (assoc-replace (cdr table) key val)))))

(define (assoc-replace* table table^)
  (if (null? table)
      table^
      (cond ((assoc (caar table) table^) => (lambda (entry)
					      (cons entry (assoc-replace* (cdr table) table^))))
	    (else (cons (car table) (assoc-replace* (cdr table) table^))))))

